﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;


namespace Inspinia_MVC5
{
    public class AdminAuthorizeAttribute: ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            ////////////**********这里放自己的逻辑代码Start************/////////////////
            string result = "";
            if (HttpContext.Current.Session["role"]!=null)//验证session是否有值，用以判断是否登录
            {
                result = HttpContext.Current.Session["role"].ToString();
            }
            if (result != "Admin")
            {
                //未登录则返回登录界面
                filterContext.HttpContext.Response.Write("<script>alert('当前会话已失效,请重新登录!');window.top.location.href='/Admins/Login'</script>");
            }

        }

    }
}